import { Table } from 'antd';
import style from '../pages/bugs.css'
import BugsModal from '../pages/bugsModal'
import moment from 'moment'
import { dicTextByCodePcode } from '../utils/dictionary'

const BugsList = ({dispatch, list: dataSource, loading, count, values }) => {

  function editHandler(id, values) {
    dispatch({
      type: 'bugs/patch',
      payload: { id, values },
    });
  }
  function page(page) {
    let pageObj = { page: page};
    let payload = values ? Object.assign(values, pageObj) : pageObj;
    dispatch({
      type: 'bugs/fetch',
      payload: payload,
    });
  }

  const columns = [{
    title: '序号',
    dataIndex: 'id',
    key: 'id',
    width: 80,
    fixed: 'left',
  },{
    title: '状态',
    dataIndex: 'type',
    key: 'type',
    width: 120,
    fixed: 'left',
    render: (text) => {
      return dicTextByCodePcode(text, 'ORDER_TYPE');
    }
  },{
    title: '模块',
    dataIndex: 'module',
    key: 'module',
    width: 150,
  },{
    title: '功能',
    dataIndex: 'func',
    width: 150,
    key: 'func',
  },{
    title: '描述',
    dataIndex: 'remark',
    width: 500,
    key: 'remark',
  },{
    title: '提出时间',
    dataIndex: 'createTime',
    width: 200,
    key: 'createTime',
    render: (text) => {
      return moment(text).format('YYYY-MM-DD HH:mm:ss');
    }
  },{
    title: '提出人',
    dataIndex: 'createUser',
    key: 'createUser',
    width: 80,
    render: (text) => {
      switch (text) {
        case 1:
          return '任光辉';
        case 2:
          return '灵芝';
        case 3:
          return '孟林杰';
        case 4:
          return '任总';
        default:
          return "----"
      }
    }
  },{
    title: '解决方案',
    dataIndex: 'solution',
    key: 'solution',
    width: 300,
  },{
    title: '处理时间',
    dataIndex: 'solveTime',
    key: 'solveTime',
    width: 200,
    render: (text) => {
      return text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '';
    }
  },{
    title: '操作',
    key: 'operation',
    fixed: 'right',
    width: 100,
    render: (text, record) => (
      <span className={style.operation}>
        <BugsModal record={record} onOk={editHandler.bind(null, record.id)}>
          <a>解决</a>
        </BugsModal>
      </span>
    ),
  }];
  return (
    <Table
      loading={loading}
      rowKey={rechod => rechod.id}
      dataSource={dataSource}
      columns={columns}
      scroll={{ x: 1800 }}
      pagination={{ total: count, onChange: page.bind(null) }}
    />
  );
};

export default BugsList;
